package com.caigou.controller.front;

import com.caigou.bean.cms.entity.CmsDictionary;
import com.caigou.bean.cms.param.SaveCooperationParam;
import com.caigou.bean.cms.param.SaverReportParam;
import com.caigou.bean.exam.entity.Users;
import com.caigou.enums.ResponseEnum;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.IClientsService;
import com.caigou.service.IFileUploadService;
import com.caigou.util.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/front")
public class FrontClientsController {
    @Resource
    private IClientsService clientsService;
    @Resource
    private IFileUploadService fileUploadService;

    /**
     * 前台用户增加合作意向
     *
     * @param param
     */
    @PostMapping("/cooperation/add")
    public Result<Integer> saveCooperationClients(@RequestBody SaveCooperationParam param, @CurrentUser Users user) {
        return clientsService.saveCooperationClients(param, user.getUserid());
    }


    /**
     * 前台用户增加寻求报道
     *
     * @param param
     */
    @PostMapping("/report/add")
    public Result<Integer> saveReportClients(@RequestBody SaverReportParam param, @CurrentUser Users user) {
        return clientsService.saveReportClients(param, user.getUserid());
    }


    /**
     * 前台上传图片
     *
     * @param
     */
    @PostMapping("/upload/picture")
    public Result<String> saveCooperationClients(HttpServletRequest request, @CurrentUser Users user) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        // 获取上传的文件
        MultipartFile multiFile = multipartRequest.getFile("file");
        return fileUploadService.uploadPicture(multiFile, user.getUserid());
    }

    /**
     * 行业列表查询
     *
     * @param
     */
    @PostMapping("/dic/industry")
    public Result<List<CmsDictionary>> getIndustryDic() {
        // 获取上传的文件
        return clientsService.findIndustryDic();
    }


    /**
     * 项目类型列表查询
     *
     * @param
     */
    @PostMapping("/dic/project")
    public Result<List<CmsDictionary>> getProjectDic() {

        // 获取上传的文件
        return clientsService.findProjectDic();
    }

    /**
     * test
     *
     * @param
     */
    @PostMapping("/test/special")
    public Result testSpecial() {

        // 获取上传的文件
        return  clientsService.testPicSpecial();

    }


}
